package org.camunda.bpm.execution;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.plugin.IPlugin;
import org.camunda.bpm.plugin.PluginManager;
import org.camunda.bpm.plugin.QueryCustPlugin;

import java.util.HashMap;
import java.util.Map;

public class ExecutionManager {
    private static PluginManager pluginManager;
    static{
        pluginManager = new PluginManager();
        pluginManager.registerPlugin("queryCust", new QueryCustPlugin());
    }
    public static Map<String, Object> executeTask(DelegateExecution execution) throws Exception {
        Object data = execution.getVariable("data");
        JSONObject json = JSONUtil.parseObj(data);

        String pluginName = json.getStr("pluginName");
        IPlugin plugin = pluginManager.getPlugin(pluginName);
        Map<String, Object> map = JSONUtil.toBean(json.getJSONObject("param"),Map.class);
        return plugin.execute(map);
    }
}
